<template>
	<!-- template部分 -->
	<view class="form-container">
		<view class="form-item">
			<text class="label">预定日期</text>
			<picker mode="date" :value="bookingDate" :start="startDate" :end="endDate" fields="day" @change="onDateChange">
				<view class="picker-display">
					<text>{{ bookingDate }}</text>
					<text class="arrow-icon">›</text>
				</view>
			</picker>
		</view>
		<view class="form-item">
			<text class="label">开始时间</text>
			<picker mode="time" :value="bookingTime" start="09:00" end="18:00" @change="onTimeChange">
				<view class="picker-display">
					<text>{{ bookingTime }}</text>
					<text class="arrow-icon">›</text>
				</view>
			</picker>
		</view>
	</view>
</template>

<script>
// script部分
function getFormatDate(date) {
	const year = date.getFullYear();
	const month = (date.getMonth() + 1).toString().padStart(2, '0');
	const day = date.getDate().toString().padStart(2, '0');
	return `${year}-${month}-${day}`;
}

export default {
	data() {
		return {
			bookingDate: getFormatDate(new Date()), // 默认今天
			startDate: getFormatDate(new Date()), // 可选的开始日期（今天）
			endDate: '2099-12-31', // 可选的结束日期
			bookingTime: '09:00'
		};
	},
	methods: {
		onDateChange(e) {
			this.bookingDate = e.detail.value;
		},
		onTimeChange(e) {
			this.bookingTime = e.detail.value;
		}
	}
};
</script>

<style scoped>
/* style部分 (与场景一完全相同，可封装为全局样式) */
.form-container {
	/* 增加一个容器，便于整体布局 */
	background-color: #f7f7f7;
	padding-top: 10px;
}
.form-item {
	display: flex;
	justify-content: space-between;
	align-items: center;
	padding: 15px;
	background-color: #ffffff;
	border-bottom: 1px solid #f0f0f0;
	font-size: 16px;
}
.form-item:last-child {
	border-bottom: none;
}
.label {
	color: #333333;
	flex-shrink: 0;
	margin-right: 15px;
}
.picker-display {
	display: flex;
	align-items: center;
	color: #888888;
	text-align: right;
	flex-grow: 1;
	justify-content: flex-end;
}
.arrow-icon {
	margin-left: 8px;
	color: #cccccc;
	font-weight: bold;
}
</style>
